﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace K3R.SqlLogging {
	public class LogConfig : ConfigurationSection {
		[ConfigurationProperty("source", IsRequired = true)]
		public string Source {
			get {
				return (string)base["source"];
			}
			set {
				base["source"] = value;
			}
		}

		[ConfigurationProperty("connectionStringName", IsRequired = true)]
		public string ConnectionStringName {
			get {
				return (string)base["connectionStringName"];
			}
			set {
				base["connectionStringName"] = value;
			}
		}

		[ConfigurationProperty("logAllEvents", DefaultValue = false)]
		public bool LogAllEvents {
			get {
				return (bool)base["logAllEvents"];
			}
			set {
				base["logAllEvents"] = value;
			}
		}
	}

	public static class Settings {
		private static LogConfig _settings = (LogConfig)ConfigurationManager.GetSection("k3r.sqlLogging");
		public static string Source {
			get {
				return _settings.Source;
			}
		}

		public static string ConnectionString {
			get {
				return ConfigurationManager.ConnectionStrings[_settings.ConnectionStringName].ConnectionString;
			}
		}

		public static bool LogAllEvents {
			get {
				return _settings.LogAllEvents;
			}
		}
	}
}
